<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumFinishTime = function (tire, arr, nums) {
      let most = [];
      most[0] = 0;
      // 2 ** 15 必然大于 arr 所以就算到这
      for (let res = 1; res <= 15; res++) {
        let tmp = Infinity;
        for (let i = 0; i < tire.length; i++) {
          let now = 0;
          for (let j = 1; j <= res; j++) {
            now += tire[i][0] * tire[i][1] ** (j - 1);
          }
          tmp = Math.min(tmp, now);
        }
        most[res] = tmp;
      }
      let dp = [0];
      for (let i = 1; i <= nums; i++) {
        dp[i] = most[i] || Infinity;
        for (let j = 1; j <= i; j++) {
          dp[i] = Math.min(dp[i], dp[i - j] + arr + (most[j] || Infinity));
        }
      }
      return dp[dp.length - 1];
    }
    console.log(minimumFinishTime(tire = [[2, 3], [3, 4]], arr = 5, nums = 4));
  </script>
</body>

</html>